home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbrowser / vbrowser.frm < prev    next >
Text File  |  1995-10-20  |  7KB  |  216 lines

  1. VERSION 2.00
  2. Begin Form browserfrm 
  3.    AutoRedraw      =   -1  'True
  4.    Caption         =   "VBrowser"
  5.    ClientHeight    =   5835
  6.    ClientLeft      =   1140
  7.    ClientTop       =   2130
  8.    ClientWidth     =   7365
  9.    Height          =   6240
  10.    Left            =   1080
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5835
  13.    ScaleWidth      =   7365
  14.    Top             =   1785
  15.    Width           =   7485
  16.    Begin TextBox Text1 
  17.       Height          =   3735
  18.       Left            =   0
  19.       MousePointer    =   1  'Arrow
  20.       MultiLine       =   -1  'True
  21.       ScrollBars      =   3  'Both
  22.       TabIndex        =   3
  23.       Top             =   2040
  24.       Width           =   7335
  25.    End
  26.    Begin MsgBlaster MsgBlaster1 
  27.       Prop8           =   "Click on ""..."" for the About Box ---->"
  28.       Prop9           =   "Click on ""..."" for the Message Center --->"
  29.       Left            =   6000
  30.       MsgList         =   VBROWSER.FRX:0000
  31.       MsgPassage      =   VBROWSER.FRX:0064
  32.       TargetName      =   "browserfrm"
  33.       Top             =   600
  34.       UserMsgs        =   VBROWSER.FRX:0096
  35.       Version         =   "2.1a"
  36.    End
  37.    Begin CommandButton connbtn 
  38.       Caption         =   "&Connect"
  39.       Height          =   495
  40.       Left            =   3000
  41.       TabIndex        =   2
  42.       Top             =   600
  43.       Width           =   1695
  44.    End
  45.    Begin TextBox conntxt 
  46.       Height          =   285
  47.       Left            =   1200
  48.       TabIndex        =   0
  49.       Text            =   "http://"
  50.       Top             =   240
  51.       Width           =   5775
  52.    End
  53.    Begin Label url 
  54.       Height          =   255
  55.       Left            =   120
  56.       TabIndex        =   5
  57.       Top             =   1680
  58.       Width           =   7095
  59.    End
  60.    Begin Label Sockstatus 
  61.       Height          =   255
  62.       Left            =   120
  63.       TabIndex        =   4
  64.       Top             =   1200
  65.       Width           =   7215
  66.    End
  67.    Begin Label Label1 
  68.       Caption         =   "Connect:"
  69.       Height          =   255
  70.       Left            =   240
  71.       TabIndex        =   1
  72.       Top             =   240
  73.       Width           =   855
  74.    End
  75. End
  76.  
  77. Sub connbtn_click ()
  78. 'Ask for index.htm
  79. document$ = "/"
  80. call_server (Trim$(conntxt.Text))
  81. End Sub
  82.  
  83. Sub conntxt_KeyPress (keyascii As Integer)
  84. If keyascii = 13 Then
  85.     connbtn_click
  86. End If
  87. End Sub
  88.  
  89. Sub Form_Load ()
  90. status% = start_winsock()
  91. End Sub
  92.  
  93. Sub Form_Unload (cancel As Integer)
  94. cancel = True
  95. quit_flag = True
  96. End Sub
  97.  
  98. Sub MsgBlaster1_Message (msgval As Integer, wparam As Integer, lparam As Long, ReturnVal As Long)
  99. nodef = True    'No further message processing(for message blaster)
  100. 'wParam is handle, lParam=event
  101.  
  102. 'SEE Winsock.txt
  103. 'NOTE NOTE NOTE NOTE
  104. 'Msgblast has a weirdness. To set the messages you want
  105. 'to trap, and the win handle, use the properties window
  106. 'for Msgblast. Click on 'message center'. If you LOOK at
  107. 'the message settings you may lose them. So if you lose
  108. 'the settings they are:
  109. 'Trap messages for 'browserfrm'
  110. 'Add user message 'EVENTMSG' (any name actually will do)
  111. 'number 8192.
  112. 'Add user message 'NAMEMSG' number 8193.
  113. 'Click the 'msg will be eaten' for both.
  114.  
  115. 'wparam=namehandle when we made call
  116. 'lparam=any error code(hi word), event type (loword)
  117. 'Set globals so anybody can use
  118. event_type% = lparam And &HFFFF&
  119. event_error% = (lparam \ &H10000) And &HFFFF&
  120. event_wparam% = wparam
  121.  
  122. If msgval = event_msg% Then
  123.     'Either got a close or a receive
  124.     If event_type% = FD_READ Then
  125.         'Received something, so read it
  126.         rxbuff$ = Space$(4096)
  127.         rxbufflen = Len(rxbuff$)
  128.         status% = recv(callsocket%, rxbuff$, rxbufflen, 0)
  129.         If status% = SOCKET_ERROR Then
  130.             status% = WSAGetLastError()
  131.             dprint "Read ERROR " + sockerror$(status%)
  132.         Else
  133.             rmsg$ = Left$(rxbuff$, status%)
  134.             If Len(current_msg$) = 0 Then
  135.                 'Start of msg
  136.                 current_msg$ = rmsg$
  137.             Else
  138.                 'next segment
  139.                 current_msg$ = current_msg$ + rmsg$
  140.             End If
  141.             dprint "Read " & Len(rmsg$) & " bytes."
  142.         End If
  143.     ElseIf event_type% = FD_CLOSE Then
  144.         'Got a close
  145.         'NOTE: Web servers will send the requested message and then
  146.         'disconnect. In theory, the received data should be received
  147.         'here BEFORE the connect is seen. i.e., our Winsock should receive
  148.         'all the data, send a receive message, and Then send the
  149.         'close message. Not so. Notice that sometimes you will get the
  150.         'close event message while their is still data to receive.
  151.         'By using a global closed status flag it appears that the data receive
  152.         'windows message will interrupt the main routine as soon as we exit
  153.         'the Msgblast routine, which throws us immediately back into the Msgblast
  154.         'receive data routine which the gets the data. It looks like the main
  155.         'recieve loop never gets a chance to recognize the closed flag. This is
  156.         'a bit too close for comfort and one should probably use the Winsock status
  157.         'call(s) to see if there is more data to be received before issuing a close
  158.         'socket. However, I have not missed any data yet. Wouldn't it be nice if
  159.         'Winsock specifications clearly explained what is happening?
  160.         dprint "Close received for socket " & wparam
  161.         'Set global flag
  162.         closed = True
  163.     End If
  164. ElseIf msgval = name_msg% Then
  165.     dprint "Name response received. lparam: " & Hex$(lparam) & "x " & lparam
  166.     got_name_response = True
  167. End If
  168.  
  169. End Sub
  170.  
  171. Sub Text1_Click ()
  172. ipt = text1.SelStart
  173.  
  174. For i = ipt To 1 Step -1
  175.     c$ = Mid$(text1.Text, i, 1)
  176.     If c$ = "[" Then
  177.         flag = True
  178.         Exit For
  179.     ElseIf c$ = "]" Then
  180.         Exit For
  181.     End If
  182.     l$ = c$ + l$
  183. Next
  184. If flag Then
  185.     flag = False
  186.     For i = ipt + 1 To Len(text1.Text)
  187.         c$ = Mid$(text1.Text, i, 1)
  188.         If c$ = "]" Then
  189.             flag = True
  190.             Exit For
  191.         ElseIf c$ = "[" Then
  192.             Exit For
  193.         End If
  194.         l$ = l$ + c$
  195.     Next
  196. End If
  197. If flag Then
  198.     document$ = ""
  199.     delim = InStr(links$, l$)
  200.     If delim Then
  201.         For i = delim - 2 To 1 Step -1
  202.             c$ = Mid$(links$, i, 1)
  203.             If c$ = "]" Then
  204.                 Exit For
  205.             Else
  206.                 document$ = c$ + document$
  207.             End If
  208.         Next
  209.         If Len(document$) Then
  210.             call_server (Trim$(conntxt.Text))
  211.         End If
  212.     End If
  213. End If
  214. End Sub
  215.  
  216.